//
//  CategoryViewController.m
//  LittleSugar
//
//  Created by zhang on 15-6-13.
//  Copyright (c) 2015年 张鑫. All rights reserved.
//

#import "CategoryViewController.h"
#import "HomeModel.h"
#import "CategoryCell.h"

@interface CategoryViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
{
    UICollectionView *_collectionView;
    
}
@property (nonatomic,strong)UICollectionView *collectionView;

@end

@implementation CategoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatCollectionView];
}

- (void)creatCollectionView {
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(kScreenSize.width/2-20, 65);
    layout.minimumInteritemSpacing = 10;
    layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    //layout.headerReferenceSize = CGSizeMake(0, 100);
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 64, kScreenSize.width, kScreenSize.height-44-84) collectionViewLayout: layout];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.collectionView registerClass:[CategoryCell class] forCellWithReuseIdentifier:@"CategoryCell"];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.showsVerticalScrollIndicator = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.collectionView];
    //分割线
    UIView *topLineView = [[UIView alloc] initWithFrame:CGRectMake(5,10, kScreenSize.width-10, 1)];
    topLineView.alpha = 0.2;
    topLineView.backgroundColor = [UIColor grayColor];
    [self.collectionView addSubview:topLineView];
    
    UIView * bottomLineView = [[UIView alloc] initWithFrame:CGRectMake(5,454, kScreenSize.width-10, 1)];
    bottomLineView.alpha = 0.2;
    bottomLineView.backgroundColor = [UIColor grayColor];
    [self.collectionView addSubview:bottomLineView];
    
    UIView * leftLineView = [[UIView alloc] initWithFrame:CGRectMake(5,11, 1, 443)];
    leftLineView.alpha = 0.2;
    leftLineView.backgroundColor = [UIColor grayColor];
    [self.collectionView addSubview:leftLineView];
    
    UIView * rightLineView = [[UIView alloc] initWithFrame:CGRectMake(kScreenSize.width-5,11, 1, 443)];
    rightLineView.alpha = 0.2;
    rightLineView.backgroundColor = [UIColor grayColor];
    [self.collectionView addSubview:rightLineView];
    
    for (NSInteger i = 0; i < 5; i++) {
        UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(10,84+i*74, kScreenSize.width-20, 1)];
        lineView.alpha = 0.2;
        lineView.backgroundColor = [UIColor grayColor];
        [self.collectionView addSubview:lineView];
    }
    for (NSInteger i = 0; i < 6; i++) {
        UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(kScreenSize.width/2-1,25+i*74, 1, 44)];
        lineView.alpha = 0.2;
        lineView.backgroundColor = [UIColor grayColor];
        [self.collectionView addSubview:lineView];
    }
    
    
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 12;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    //从复用队列获取可用的cell
    CategoryCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CategoryCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"xxxx");
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(150 ,64);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
